home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 025a / prgmchk.zip / PARENCHK.BAS < prev    next >
BASIC Source File  |  1991-07-23  |  3KB  |  92 lines

  1. '     PARENCHK.BAS - parentheses checker routine - This routine
  2. '     compares number of ( vs number of ) per line and prints the line if the
  3. '     totals don't agree:  If the totals are off but the line ends with a +
  4. '     (Rbase continuation symbol) then the routine skips to the next line
  5. '     before comparing totals.  The routine also checks the sequence of 
  6. '     opening and closing parentheses and flags the location within a line
  7. '     where the number of closing exceeds the number of opening parentheses.
  8. '                                            created 11 July 91; Wm Driskell
  9.  
  10. CLS
  11. PRINT "Parentheses Checker"
  12. PRINT "-------------------"
  13. PRINT
  14.  
  15. INPUT "Enter name of file to check: ", ifile$
  16. INPUT "Enter name of file for output: ", ofile$
  17. OPEN "I", #1, ifile$
  18. OPEN "O", #2, ofile$
  19. PRINT #2, "file: "; ifile$
  20. PRINT #2,
  21. PRINT #2, "Line #: total left paren and right paren counts"
  22. PRINT
  23. PRINT "Line #: total left paren and right paren counts"
  24.  
  25. ' setup counters and constants
  26.  rpknt = 0      'counters
  27.  lpknt = 0
  28.  lp$ = "("      'search strings
  29.  rp$ = ")"
  30.  lx = 1         'position within text line
  31.  rx = 1
  32.  
  33.  ' get line and parse for parentheses
  34.  DO UNTIL EOF(1)
  35.   LINE INPUT #1, a$
  36.   lineknt = lineknt + 1
  37.   DO
  38.     l = INSTR(lx, a$, lp$)
  39.     r = INSTR(rx, a$, rp$)
  40.     IF l > 0 THEN
  41.      lpknt = lpknt + 1
  42.      lx = l + 1
  43.     END IF
  44.     IF r > 0 THEN
  45.      rpknt = rpknt + 1
  46.      rx = r + 1
  47.     END IF
  48.     IF rx < lx AND lpknt <= rpknt THEN
  49.      PRINT "==>"; lineknt, "**** Too Many Right Parentheses ****"
  50.      PRINT #2, "==>"; lineknt, "**** Too Many Right Parentheses ****"
  51.      PRINT a$
  52.      PRINT #2, a$
  53.      PRINT TAB(rx - 1); "^"
  54.      PRINT #2, TAB(rx - 1); "^"
  55.     END IF
  56.   LOOP UNTIL l = 0 AND r = 0
  57.   IF lpknt <> rpknt AND RIGHT$(a$, 1) <> "+" THEN
  58.    PRINT "==>"; lineknt; ": "; lpknt; rpknt
  59.    PRINT a$
  60.    PRINT #2, "==>"; lineknt; ": "; lpknt; rpknt
  61.    PRINT #2, a$
  62.   END IF
  63.   lx = 1
  64.   rx = 1
  65.  LOOP
  66.  PRINT
  67.  PRINT ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
  68.  PRINT
  69.  PRINT "total lines processed: "; lineknt
  70.  PRINT "total number of parentheses: left - "; lpknt, "right - "; rpknt
  71.  PRINT
  72.  PRINT "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
  73.  PRINT
  74.  PRINT #2,
  75.  PRINT #2, ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
  76.  PRINT #2,
  77.  PRINT #2, "total lines processed: "; lineknt
  78.  PRINT #2, "total number of parentheses: left -"; lpknt, "right -"; rpknt
  79.  PRINT #2,
  80.  PRINT #2, ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
  81.  PRINT #2,
  82.  CLOSE #2
  83. END
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.